package com.hm.system.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.hm.common.annotation.AuthenticationAnnotation;
import com.hm.common.annotation.RequestPlanAnnotation;
import com.hm.common.model.ControllerResult;
import com.hm.common.model.PageInfo;
import com.hm.common.util.RequestLogDef;
import com.hm.system.mongo.vo.log.RequestPlanLogVo;
import com.hm.system.share.service.mongo.log.RequestPlanLogService;
import com.hm.system.util.SystemConfigDef.Api.Rest;
import com.hm.system.web.su.BaseController;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * @author shishun.wang
 * @date 2016年6月3日 上午12:12:22
 * @version 1.0
 * @describe 前端请求日志
 */
@ResponseBody
@RestController
@RequestMapping(value = Rest.Log.REST_LOG_REQUEST_PLAN_INFO)
public class RequestPlanLogController extends BaseController {

	public static final String swaggerTag = "前端请求日志";

	@Autowired
	private RequestPlanLogService requestPlanLogService;

	@AuthenticationAnnotation
	@RequestMapping(value = "/{pageNumber}/{pageSize}", method = RequestMethod.GET)
	@ApiOperation(value = "获取前端请求日志数据", httpMethod = "GET", notes = "分页获取前端请求日志数据", tags = swaggerTag)
	@RequestPlanAnnotation(title = "获取前端请求日志数据", content = "分页获取前端请求日志数据")
	public ResponseEntity<ControllerResult<PageInfo<RequestPlanLogVo>>> queryRequestPlanLog(
			@ApiParam(required = true, name = "pageNumber", value = "分页号(第一页值为1,小于1则默认返回第一页)") @PathVariable("pageNumber") Integer pageNumber,
			@ApiParam(required = true, name = "pageSize", value = "分页大小") @PathVariable("pageSize") Integer pageSize,
			@ApiParam(required = false, name = "remoteIpAddress", value = "ip地址") @RequestParam(required = false) String remoteIpAddress,
			@ApiParam(required = false, name = "requestUrl", value = "请求地址") @RequestParam(required = false) String requestUrl,
			@ApiParam(required = true, name = "startTime", value = "开始时间") @RequestParam(required = true) Long startTime,
			@ApiParam(required = false, name = "endTime", value = "结束时间") @RequestParam(required = false) Long endTime,
			@ApiParam(required = true, name = "requestLog", value = "日志类型") @RequestParam RequestLogDef requestLog) {
		try {
			return ControllerResult.success(requestPlanLogService.queryRequestPlanLog(remoteIpAddress, requestUrl,
					startTime, endTime, requestLog, pageNumber, pageSize));
		} catch (Exception e) {
			return ControllerResult.failed(e);
		}
	}
}
